# app.py
from fastapi import FastAPI
from routes import router

app = FastAPI()
app.include_router(router)


from fastapi import FastAPI
from routes import router, CustomException
from fastapi.responses import JSONResponse
from fastapi import Request

app = FastAPI()

# 注册自定义异常处理器
@app.exception_handler(CustomException)
async def custom_exception_handler(request: Request, exc: CustomException):
    return JSONResponse(
        status_code=exc.code,
        content={"code": exc.code, "msg": exc.msg, "data": {}}
    )

# 将路由添加到应用中
app.include_router(router)

@app.get("/")
async def read_root():
    return {"message": "欢迎使用商城 API"}

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)
